package gui;

import java.io.IOException;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import rede.MostraDados;
import rede.Servidor;

/**
 * @author tiagosn
 */
public class JanelaServidor extends javax.swing.JFrame implements MostraDados{
    Servidor servidor;

    public JanelaServidor(int porta) throws IOException {
        initComponents();
        servidor = new Servidor(this, porta);
    }
    
    public void atualizarListaClientes(ArrayList<String> logins, ArrayList<String> ips) {
        DefaultTableModel modelo = (DefaultTableModel)jTStatus.getModel();

        // Limpa Tabela
        modelo.setDataVector(new String [][] {}, new String [] {"Login", "IP"});

        // Preenche Tabela
        int cnt;
        for(cnt = 0; cnt < logins.size(); ++cnt){
            System.out.println(ips.get(cnt));
            modelo.insertRow(modelo.getRowCount(), new String[] {logins.get(cnt), ips.get(cnt).substring(1)});
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTStatus = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTStatus.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Login", "IP"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTStatus.setEnabled(false);
        jTStatus.setShowHorizontalLines(false);
        jTStatus.setShowVerticalLines(false);
        jScrollPane1.setViewportView(jTStatus);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTStatus;
    // End of variables declaration//GEN-END:variables
}
